<template>
	<!-- 佣金 申请提现 -->
    <div class="brokerage-AddWithdraw">
      <!-- 导航 -->
      <tz-breadcrumb  :pathArr='[{"name": "佣金"},{"name": "申请提现", "url": "/AddWithdraw"}]'></tz-breadcrumb>
              <!-- 数据表单 -->
<div style="margin: 20px;"></div>
<el-form class="form" label-width="80px">
  <el-form-item label="当前余额">
    <el-input class="form-input" style="width:200px;" disabled="" v-model="balance"></el-input>
  </el-form-item>
  <el-form-item label="提现金额">
    <el-input  class="form-input" style="width:200px;" v-model="formInline.money"></el-input>
  </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onWithdraw">确认提现</el-button>
    </el-form-item>
  </el-form>
    </div>
</template>
<script>
import tzBreadcrumb from './../../components/breadcrumb/breadcrumb.vue';
import api from './../../api/api';
import http from './../../config/index';
export default {
  components: {
    'tz-breadcrumb': tzBreadcrumb
  },
  data () {
    return {
      // 表单数据
      formInline: {
        money: 0
      },
      tableData: [],
      balance: 0
    };
  },
  created () {
    this.getUserBalance();
  },
  methods: {
    getUserBalance () {
      let that = this;
      http.post(api.userInfo, {
        token: localStorage.getItem('token')
      }, response => {
        let content = response.data[0];
        that.balance = content.data.balance;
        // that.tableData.push({date: content.id, name: '提现编号'});
        // that.tableData.push({date: content.uid, name: '提现用户编号'});
      }, err => {
        console.log(err);
      });
    },
    onWithdraw () {
      console.log(1);
      let that = this;
      that.requestData();
    },
    requestData () {
      let that = this;
      http.post(api.AddWithdrawalOrder, {
        token: localStorage.getItem('token'),
        money: that.formInline.money
      }, response => {
        if (response.code === 10001 || response.code === '10001') {
          // console.log('aaa');
          that.balance = (that.balance * 100 - that.formInline.money * 100) / 100;
          that.$message({
            message: '提现申请已提交',
            type: 'success'
          });
        } else {
          // console.log('bbb');
          // alert(111);
          that.$message({
            message: response.msg,
            type: 'warning'
          });
        }
      }, err => {
        console.log(err);
      });
    }
  }
};
</script>

<style lang="stylus" scoped>
.form
  padding: 2rem
  margin-top: 15px
  margin-bottom: 12px
  box-sizing: border-box
  background: #fff
  box-shadow: 1px 1px 1px #999
  .form-item
    display: inline-block
    margin-right: 35px
    label
      font-size: 14px
      color: #333
      width: 70px
      display: inline-block
    .form-input, .form-select
      width: 200px
  .line
    height: 15px
.server-item
  width: 20px
  height: 20px
  margin: 5px
</style>
